anfederico / clairvoyant

Software designed to identify and monitor social/historical cues for short term stock movement
MIT License
2.42k stars 772 forks source link

Error when running example: ufunc 'isfinite' not supported for the input types #34

Open mathiasi opened 4 years ago

mathiasi commented 4 years ago

I'm trying to run the example, though it has been modified as per the guidance in other issues. Here is the code:

from clairvoyant.engine import Backtest
import pandas as pd

features  = ["X1", "X2"]   # Financial indicators of choice
trainStart = 0               # Start of training period
trainEnd   = 100             # End of training period
testStart  = 200             # Start of testing period
testEnd    = 300            # End of testing period
buyThreshold  = 0.65         # Confidence threshold for predicting buy (default = 0.65) 
sellThreshold = 0.65         # 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
data = pd.read_csv("clair-data.csv", date_parser=['date'])
data = data.round(3)                                    

# Start backtesting and optionally modify SVC parameters
# Available paramaters can be found at: http://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html
backtest.start(data, kernel='rbf', C=1, gamma=10)
backtest.conditions()
backtest.statistics()  
backtest.visualize('X1','X2')

and this is the output I'm getting:

------------ Data Features ------------

X1: X1
X2: X2

---------------------------------------

----------- Model Arguments -----------

kernel: rbf
C: 1
gamma: 10

---------------------------------------

---------  Engine Conditions ----------

Training: 4/15/16 -- 9/7/16
Testing:  1/31/17 -- 6/23/17
Buy Threshold: 65.0%
Sell Threshold: 65.0%
Continued Training: False

---------------------------------------

------------- Statistics --------------

Total Buys: 0
Buy Accuracy: 0.0%
Total Sells: 11
Sell Accuracy: 27.27%

---------------------------------------

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-480e8274c951> in <module>
     23 backtest.conditions()
     24 backtest.statistics()
---> 25 backtest.visualize('X1','X2')

~/.local/lib/python3.6/site-packages/clairvoyant/engine.py in visualize(self, name, width, height, stepsize)
    170         xx, yy = meshgrid(arange(x_min, x_max, stepsize), arange(y_min, y_max, stepsize))
    171 
--> 172         pyplot.figure(figsize=(width, height))
    173         cm = pyplot.cm.RdBu  # Red/Blue gradients
    174         rb = ListedColormap(['#FF312E', '#6E8894']) # Red = 0 (Negative) / Blue = 1 (Positve)

~/.local/lib/python3.6/site-packages/matplotlib/pyplot.py in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, clear, **kwargs)
    543                                         frameon=frameon,
    544                                         FigureClass=FigureClass,
--> 545                                         **kwargs)
    546 
    547         if figLabel:

~/.local/lib/python3.6/site-packages/matplotlib/backend_bases.py in new_figure_manager(cls, num, *args, **kwargs)
   3256         from matplotlib.figure import Figure
   3257         fig_cls = kwargs.pop('FigureClass', Figure)
-> 3258         fig = fig_cls(*args, **kwargs)
   3259         return cls.new_figure_manager_given_figure(num, fig)
   3260 

~/.local/lib/python3.6/site-packages/matplotlib/figure.py in __init__(self, figsize, dpi, facecolor, edgecolor, linewidth, frameon, subplotpars, tight_layout, constrained_layout)
    346             frameon = rcParams['figure.frameon']
    347 
--> 348         if not np.isfinite(figsize).all():
    349             raise ValueError('figure size must be finite not '
    350                              '{}'.format(figsize))

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

Do you have any idea what this could be? Is there other things that I need to adjust to run the example?