Hi
So I'm trying to write an Algorythm to trade a list of stocks. Unfortuantely I'm failing to even read in the strocks. I can't load a backtest as it fails before completing. Below is my code
from AlgorithmImports import *
import datetime
from io import StringIO
#import os
import pandas as pd
import traceback
#import typing
#import QuantConnect
#import requests
#import operator
#import math
#from SmartRollingWindow import *
#endregion
class OptimizedTransdimensionalReplicator(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 10, 1) # Set Start Date
self.SetCash(100000) # Set Strategy Cash
#tickers = ["AAPL", "MSFT", "TSLA"]
try:
data = StringIO(self.Download("https://www.dropbox.com/s/r1jwm0bhqsb4c02/Tips_20220304.csv?dl=0"))
self.df1 = pd.read_csv(data)
except Exception:
ex = traceback.format_exc
print(ex)
tickers = SelectSymbols()
# self.symbols = [Symbol.Create(ticker, SecurityType.Equity, Market.USA)]
self.SetUniverseSelection(FineFundamentalUniverseSelectionModel(self.CoarseSelectionFunction, self.FineSelectionFunction))
self.UniverseSettings.Resolution = Resolution.Daily
def SelectSymbols(self):
symbols = []
# self.df2 = self.df1.groupby(['Symbol']).count()
# for i in self.df2.index:
# print(df2['Symbol'][i])
# symbols.append(df2['Symbol'][i])
# return symbols
def func(self,x):
return self.Securities[x].Fundamentals.ValuationRatios.NormalizedPERatio
def OnData(self, data):
selected = None
def CoarseSelectionFunction(self, coarse):
return self.symbols
def FineSelectionFunction(self, fine):
return self.symbols
The Error message I get is
During the algorithm initialization, the following exception has occurred: ParserError : Error tokenizing data. C error: Expected 1 fields in line 2, saw 2
at pandas._libs.parsers.raise_parser_error
File "parsers.pyx" in parsers.pyx: line 2131
ParserError : Error tokenizing data. C error: Expected 1 fields in line 3, saw 2
Newoptionz
I'm reviewing
Newoptionz
Well, I copy that example above ‘DropboxCoarseFineAlgorithm’ and paste it in a new Algorithm and get the following remarks in ‘Cloud terminal’ - ‘1|
8:36:53 Builder projects can not save file changes.'
I see a number of active environments - in the right window with the symbols ‘<>’ - I closed them all. I repasted the ‘‘DropboxCoarseFineAlgorithm’ and get the following
Building Project ID: 11103668 Content Signature: 5fd31bcadaf304daaf02e47d9243dc9e
no backtest window or anything. I will try open a support ticket.
Also I can't add a research notebook in the new coding environmnet.
Fred Painchaud
Hi Newoptionz,
You could try this:
"https://www.dropbox.com/s/r1jwm0bhqsb4c02/Tips_20220304.csv?dl=1"
Note dl=1 at the end.
With dl=0, you are downloading a web page (so HTML code) not a “pure” CSV file.
Fred
Newoptionz
Thanks
Now I'm learning more about Pandas and groupby. The attached code is not trading the list yet, but I will now work towards that and share my results.
Newoptionz
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!