Giter Site home page Giter Site logo

Comments (7)

jordan-green-zz avatar jordan-green-zz commented on June 3, 2024

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.

arambula1980 avatar arambula1980 commented on June 3, 2024

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.

jordan-green-zz avatar jordan-green-zz commented on June 3, 2024

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.

mattpetersen avatar mattpetersen commented on June 3, 2024

Glad it seems to be working :) Can we close this issue as it's not actually a bug?

from clairvoyant.

arambula1980 avatar arambula1980 commented on June 3, 2024

Yes, lets close it ... Thanks !!

from clairvoyant.

santosh1383 avatar santosh1383 commented on June 3, 2024

What did you...i am still getting error : NameError: name 'backtester' is not defined

from clairvoyant.

santosh1383 avatar santosh1383 commented on June 3, 2024

or another error: AttributeError: 'Backtest' object has no attribute 'Simulation'

from clairvoyant.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.