發表文章

林逸民期末考

圖片
import csv #德明科大林逸民修改11與16列 f = open('00960.csv','r',encoding='utf-8') csv_reader = csv.reader(f) header, rows = [], [] #宣告空白串列(陣列,清單) header = next(csv_reader) #串列header存放第一列標題 for row in csv_reader: #逐列讀檔案、附加append於rows串列 rows.append(row) f.close() idSet = set() component = dict() #zeros = [0 for i in range(21)] for row in rows: for j in range(0, 21): idSet.add(row[j*4]) for id in idSet: component[id] = [0 for i in range(21)] #取代原來的zeros for row in rows: for j in range(0, 21): if row[j*4+3] != '': component[row[j*4]][j] = row[j*4 + 3] print(row[j*4+1],component[row[j*4]]) for id in idSet: print(id, component[id]) 原來程式碼 修改後程式碼

林逸民野村投信全球航運龍頭00960分散風險效果

圖片
程式碼 style=background-color;blue import csv #輸入import輸出export,輸入csv套件 import math #輸入math套件 from tkinter import * #或者import tkinter as tk scale = 2000 # 放大倍率 base = 600 # 圖形中心高度 def transposeMatrix(m): #自訂轉置transpose函數 N = [] for j in range(len(m[0])): row = [] for i in range(len(m)): row.append(m[i][j]) N.append(row) return N def getMatrixMinor(m,i,j): return [row[:j] + row[j+1:] for row in (m[:i]+m[i+1:])] def getMatrixDeternminant(m): #base case for 2x2 matrix if len(m) == 2: return m[0][0]*m[1][1]-m[0][1]*m[1][0] determinant = 0 for c in range(len(m)): determinant += ((-1)**c)*m[0][c]*getMatrixDeternminant(getMatrixMinor(m,0,c)) return determinant def getMatrixInverse(m): determinant = getMatrixDeternminant(m) if len(m) == 2: #處理2x2方陣 return [[m[1][1]/determinant, -1*m[0][1]/determinant], [-1*m[1][0]/det...

林逸民「python讀入csv檔案計算黃金交叉和死亡交叉」 5月 07, 2026

圖片
 import pandas as pd import numpy as np # 1. 讀取 CSV 檔案 (假設日期欄位為 Date,並將其設為索引) df = pd.read_csv('stock_data.csv', parse_dates=['Date'], index_col='Date') # 2. 設定短天期與長天期的移動平均線 (例如:短期 5日, 長期 20日) short_window = 5 long_window = 20 # 計算均線 df['Short_MA'] = df['Close'].rolling(window=short_window).mean() df['Long_MA'] = df['Close'].rolling(window=long_window).mean() # 3. 標示黃金交叉與死亡交叉 # 黃金交叉:短期均線向上突破長期均線 # 死亡交叉:短期均線向下跌破長期均線 df['Signal'] = 0.0 df['Signal'][short_window:] = np.where(df['Short_MA'][short_window:] > df['Long_MA'][short_window:], 1.0, 0.0) # 計算訊號的變化 (找出交叉點) df['Position'] = df['Signal'].diff() # 4. 篩選出交叉的日期 # Position == 1.0 代表黃金交叉,Position == -1.0 代表死亡交叉 golden_crosses = df[df['Position'] == 1.0] death_crosses = df[df['Position'] == -1.0] print("--- 黃金交叉日期 ---") print(golden_crosses.index.strftime('%Y-%m-%d')) print("\n--- 死亡交叉日期 ---...

林逸民蒙地卡羅模擬,遊戲驛站軋空事件

林逸民蒙地卡羅模擬資產價格 切割期數 0 1 2 3 4 500 1000 心得 複習/CSS=cascading style sheets=階層樣式列表 P=段落,PARAGRAPH段落,SCRIPT腳本,JAVASCRIPT區塊 程式設計是一門結合理性與創造力的學習過程。從一開始接觸語法時的困惑,到逐漸能夠理解邏輯與結構,過程雖然充滿挑戰,但也帶來成就感。撰寫程式不只是讓電腦執行指令,更是一種解決問題的思維訓練。當遇到錯誤時,需要耐心除錯與分析,培養細心與邏輯能力。同時,透過不斷練習與查詢資料,也提升自學能力。程式設計讓我學會將複雜問題拆解,逐步完成目標,這種能力也能應用在生活各方面,是一項值得持續精進的技能。 影片 蒙地卡羅模擬 遊戲驛站軋空事件

林逸民PRE STYLE='BORDER: PINK 10PX SOLID' 4月 09, 2026

圖片
 

林逸民蒙地卡羅證券價格模擬

林逸民蒙地卡羅模擬資產價格 切割期數 0 1 2 3 4 5 6 7 8 9 10 20 30 40 50 100

EXCEL繪製投資效率前緣

圖片