#今天要拷貝到vs code 寫上自己名字
#程式交易資料來源,即時資料、讀取電腦資料、最低階的練習、在程式碼中輸入
title = ["日期", "收盤", "決策","
部位"]
rows = []
rows.append(title)
rows.append(["2024/6/17",15.1,0,0])
rows.append(["2024/6/18",15.8,0,0])
rows.append(["2024/6/19",18.1,1,1])
rows.append(["2024/6/20",19.2,0,1])
rows.append(["2024/6/21",20.1,0,1])
for i in range(len(rows)):
print(rows[i])
for i in range(1, len(rows)):
if rows[i][3]==1:#如果做多
gain = rows[i][1]-rows[i-1][1]
rows[i].append(gain)#增加一個欄位今天損益
elif rows[i][3]==-1:#如果做空
gain = rows[i-1][1]-rows[i][1]#昨天扣除今天
rows[i].append(gain)
else:
rows[i].append(0.0)
for i in range(1,len(rows)):
print(rows[i])
輸出 Excel學習 Option Explicit '必須宣告所有變數variables Dim i, j As Integer '宣告dimension i, j 是整數integer Public Sub RayWu() Cells(1, 1).Value = "RayWu xxx" Cells(1, 1).Font.Size = 20 Cells(1, 1).Interior.Color = RGB(128, 0, 0) Cells(1, 1).Font.Color = RGB(255, 255, 255) End Sub Public Sub RayWu迴圈() For i = 2 To 10 For j = 1 To 6 Cells(i, j).Value = (2010 + i) & "年" Next Next End Sub
Public Sub 劉任昌第一個城市() '練習寫迴圈 VBA=Visual Basic Application 'Dim i, j As Integer j = 7 For i = 1 To 15 Cells(i, j).Value = i * i Next 'VBA迴圈的結束Next, C或Javascript {}定義迴圈範圍 'VBA程式語言寫Microsoft Office 巨集 Macro小程式 End Sub 只顯示部分資訊
期末考完成.https://takmingfinanc.blogspot.com/2024/06/d11017202.html
回覆刪除