Hello,
I am new to Quantconnect.
I am trying to create a track of my portfolio value, by creating a list of it.
Running the following code, i can see that the variable self.Portfolio.TotalPortfolioValue doesn't update, and the list is not extended.
Maybe this is because of some python / C# incompability ?
__________
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Indicators")
AddReference("QuantConnect.Common")
from System import *
from QuantConnect import *
from QuantConnect.Data import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *
from QuantConnect.Packets import *
from datetime import timedelta
import numpy as np
class BasicTemplateForexAlgorithm(QCAlgorithm):
def Initialize(self):
# Set the cash we'd like to use for our backtest
self.SetCash(100000)
# Start and end dates for the backtest.
self.SetStartDate(2013, 10, 7)
self.SetEndDate(2013, 10, 11)
# Add FOREX contract you want to trade
# find available contracts here https://www.quantconnect.com/data#forex/oanda/cfd
self.AddForex("EURUSD", Resolution.Minute)
self.AddForex("GBPUSD", Resolution.Minute)
self.AddForex("EURGBP", Resolution.Minute)
self.History(5, Resolution.Daily)
self.History(5, Resolution.Hour)
self.History(5, Resolution.Minute)
history = self.History(TimeSpan.FromSeconds(5), Resolution.Second)
for data in sorted(history, key=lambda x: x.Time):
for key in data.Keys:
self.Log(str(key.Value) + ": " + str(data.Time) + " > " + str(data[key].Value))
def OnData(self, slice):
self.Portfolio_value = list()
for key in slice.Keys:
#print(str(key.Value) + ": " + str(slice.Time) + " > " + str(slice[key].Value))
self.Log("Key + ID " + str(key.ID))
self.Log("Time " + str(slice.Time))
self.Log("Open " + str(slice[key].Open))
self.Log("High " + str(slice[key].High))
self.Log("Low " + str(slice[key].Low))
self.Log("Close " + str(slice[key].Close))
self.Portfolio_value.append(self.Portfolio.TotalPortfolioValue)
self.Log("Portfolio value : " + str(self.Portfolio_value))
self.Log("Portfolio value : " + str(len(self.Portfolio_value)))