Comments (7)
Hi arambula,
I assume that you've copied the second code snippet from the readme page into 'stock6.py'
NameError: name 'backtest' is not defined
is telling you that you have not created an object called backtest. This object is defined just after the imports and parameters are set in the first code snippet in the readme page. Try copying that snippet in before your code in stock6.py and then delete whatever you don't want/need.
I hope that helps
from clairvoyant.
Hi Jordan,
Thanks for your quick reply.
Yes, Here is my code up to this point :
from clairvoyant.engine import Backtest
import pandas as pd
features = ["x1", "x2", "x3"] # Financial indicators of choice (
trainStart = 0 # Start of training period
trainEnd = 551 # End of training period
testStart = 552 # Start of testing period
testEnd = 723 # End of testing period
buyThreshold = 0.40 # Confidence threshold for predicting buy (default = 0.65)
sellThreshold = 0.40 # Confidence threshold for predicting sell (default = 0.65)
continuedTraining = False # Continue training during testing period? (default = false)
# Initialize backtester
backtest = Backtest(features, trainStart, trainEnd, testStart, testEnd, buyThreshold, sellThreshold,
continuedTraining)
# A little bit of pre-processing
df = pd.read_csv("stock1.MX.csv", date_parser=['date'])
df = df.fillna(0)
df = df.round(3)
def logic(account, today, prediction, confidence):
if prediction == 1:
Risk = 0.30
EntryPrice = today['close']
EntryCapital = account.BuyingPower*Risk
if EntryCapital >= 0:
account.EnterPosition('Long', EntryCapital, EntryPrice)
if prediction == -1:
ExitPrice = today['close']
for Position in account.Positions:
if Position.Type == 'Long':
account.ClosePosition(Position, 1.0, ExitPrice)
simulation = backtest.Simulation(features, trainStart, trainEnd, testStart, testEnd, buyThreshold,
sellThreshold, continuedTraining)
simulation.start(data, 1000, logic, kernel='rbf', C=1, gamma=10)
simulation.statistics()
simulation.chart('stock1')`
Not sure why I am getting the error, since the first example runs fine. And with the second example, backtest is there as well.
Any ideas ?
Thanks.
from clairvoyant.
Hi,
Your code runs fine beyond that point on my system - I do get an error that Simulation is not defined but that is due to the back you have referenced it as backtest.Simulation and I believe Simulation is actually a class within clairvoyant.engine. ("I've actually not used this software myself beyond getting it running - I'm just starting to play with it a little so I might not be right there).
You should be able to import it like so:
from clairvoyant.engine import Backtest, Simulation
Your code runs into an index problem then, which may be your code or my data (I threw a random datafile in), but I don't have time to look through that I'm afraid.
As for your import problem - do you have more than one version of python on your machine?
IE do you have both python 2.7 and python3 (this is common) as they will have different install locations for packages.
Check which python you're using by typing which python
(on unix) and ensure it's the same one you used when you ran the first script. Or, you can try reinstalling the package:
pip install --upgrade --force-reinstall clairvoyant
I hope this helps, and good luck learning python!
from clairvoyant.
Glad it seems to be working :) Can we close this issue as it's not actually a bug?
from clairvoyant.
Yes, lets close it ... Thanks !!
from clairvoyant.
What did you...i am still getting error : NameError: name 'backtester' is not defined
from clairvoyant.
or another error: AttributeError: 'Backtest' object has no attribute 'Simulation'
from clairvoyant.
Related Issues (20)
- Bug in predict_proba? HOT 1
- Working example HOT 1
- ImportError: No module named 'backtester' HOT 7
- Dimensionality reduction with t-SNE
- Does trainStart and trainEnd not support date formats anymore? HOT 3
- IndexError: single positional indexer is out-of-bounds HOT 1
- IndexError: single positional indexer is out-of-bounds HOT 2
- SyntaxError: invalid syntax : "self.svc = SVC(**kwargs, probability=True)" HOT 4
- TypeError: a float is required: "self.svc.fit(self.scaler.transform(self.XX), self.yy)" HOT 5
- KeyError: 'EMA' HOT 1
- TypeError: 'str' object cannot be interpreted as an integer when running backtest.start() HOT 5
- data named 'SBUX.csv' HOT 1
- Code seems incorrect HOT 1
- Could you supply the file("SBUX.csv")? HOT 2
- Cannot Run Code HOT 4
- Error when running example: ufunc 'isfinite' not supported for the input types
- #HELP# Some errors appeared unusually HOT 1
- Project dependencies have API risk issues HOT 1
- Stock prediction tool
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clairvoyant.