Git Product home page Git Product logo

aiif's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aiif's Issues

11_risk_management.ipynb - LinAlgError: SVD did not converge in Linear Least Squares

Hi, first of all, thanks for writing the book. It is amazing.

When running the notebook 11_risk_management.ipynb the step

tradingbot.plot_performance(agent)

it is failing with the following error:

---------------------------------------------------------------------------
LinAlgError                               Traceback (most recent call last)
<ipython-input-13-80d9132e183d> in <module>
----> 1 tradingbot.plot_performance(agent)
      2 # plt.savefig('../../images/ch11/figure_rm_02.png');

D:\trade-projects\aiif\code\tradingbot.py in plot_performance(agent)
    180     plt.figure(figsize=(10, 6))
    181     x = range(1, len(agent.performances) + 1)
--> 182     y = np.polyval(np.polyfit(x, agent.performances, deg=3), x)
    183     plt.plot(x, agent.performances[:], label='training')
    184     plt.plot(x, y, 'r--', label='regression (train)')

<__array_function__ internals> in polyfit(*args, **kwargs)

D:\anaconda3\envs\aiif\lib\site-packages\numpy\lib\polynomial.py in polyfit(x, y, deg, rcond, full, w, cov)
    629     scale = NX.sqrt((lhs*lhs).sum(axis=0))
    630     lhs /= scale
--> 631     c, resids, rank, s = lstsq(lhs, rhs, rcond)
    632     c = (c.T/scale).T  # broadcast scale coefficients
    633 

<__array_function__ internals> in lstsq(*args, **kwargs)

D:\anaconda3\envs\aiif\lib\site-packages\numpy\linalg\linalg.py in lstsq(a, b, rcond)
   2257         # lapack can't handle n_rhs = 0 - so allocate the array one larger in that axis
   2258         b = zeros(b.shape[:-2] + (m, n_rhs + 1), dtype=b.dtype)
-> 2259     x, resids, rank, s = gufunc(a, b, rcond, signature=signature, extobj=extobj)
   2260     if m == 0:
   2261         x[...] = 0

D:\anaconda3\envs\aiif\lib\site-packages\numpy\linalg\linalg.py in _raise_linalgerror_lstsq(err, flag)
    107 
    108 def _raise_linalgerror_lstsq(err, flag):
--> 109     raise LinAlgError("SVD did not converge in Linear Least Squares")
    110 
    111 def get_linalg_error_extobj(callback):

LinAlgError: SVD did not converge in Linear Least Squares

Seems like there are inf or nan values in the data.

Could we add dropna(inplace=True) ?

12_execution_deployment.ipynb

Hello. First thanks for the knowledge. Second when i run the trading bot and import oandaenv.py i am getting this error:

KeyError Traceback (most recent call last)
in

/content/oandaenv.py in init(self, symbol, start, end, granularity, price, features, window, lags, leverage, min_accuracy, min_performance, mu, std)
35 self.granularity = granularity
36 self.price = price
---> 37 self.api = tpqoa.tpqoa('aiif.cfg')
38 self.features = features
39 self.n_features = len(features)

1 frames
/usr/lib/python3.9/configparser.py in getitem(self, key)
961 def getitem(self, key):
962 if key != self.default_section and not self.has_section(key):
--> 963 raise KeyError(key)
964 return self._proxies[key]
965

KeyError: 'oanda'

I am getting this error when i run this code

%%time
learn_env = oe.OandaEnv(symbol=symbol,
start=f'{date} 08:00:00',
end=f'{date} 13:00:00',
granularity='S30',
price='M',
features=features,
window=20,
lags=3,
leverage=20,
min_accuracy=0.4,
min_performance=0.85
)
For the aiif.cfg this the structure and my credentials are correct as i had used it to run the code that was before this and was able to get historical data and make orders.

[oanda]
account_id = 101-001-25418976-001
access_token = 55c13668f2efac009674500a66b87a83-0aeb2e9467fa8b4d0bca1c29815cb911
account_type = practice

Running oandatb.py failes

Hello,
I'm facing an issue when i'm running oandatb.py because the below error although i saw that inside tradingbot.py eager mode is disabled i'm using the same version TF 2.3:
Traceback (most recent call last):
File "oandatb.py", line 118, in
otb.stream_data(agent.learn_env.symbol)
File "/home/ramy/aiif-main/code/aiif/lib/python3.8/site-packages/tpqoa/tpqoa.py", line 285, in stream_data
self.on_success(msg.time,
File "oandatb.py", line 90, in on_success
prediction = np.argmax(self.agent.model.predict(state)[0, 0])
File "/home/ramy/aiif-main/code/aiif/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py", line 1577, in predict
version_utils.disallow_legacy_graph('Model', 'predict')
File "/home/ramy/aiif-main/code/aiif/lib/python3.8/site-packages/tensorflow/python/keras/utils/version_utils.py", line 122, in disallow_legacy_graph
raise ValueError(error_msg)
ValueError: Calling Model.predict in graph mode is not supported when the Model instance was constructed with eager mode enabled. Please construct your Model instance in graph mode or call Model.predict with eager mode enabled.

Confusion regarding use of "bar-1" instead of "bar+1"

Sir,

Here is the piece of code taken from the backtest_strategy method:

        state = self.env.get_state(bar)
        action = np.argmax(self.model.predict(
                    self._reshape(state.values))[0, 0])
        position = 1 if action == 1 else -1
        if self.position in [0, -1] and position == 1:
            if self.verbose:
                print(50 * '-')
                print(f'{date} | *** GOING LONG ***')
            if self.position == -1:
                self.place_buy_order(bar - 1, units=-self.units)
            self.place_buy_order(bar - 1,
                                 amount=self.current_balance)
            if self.verbose:
                self.print_net_wealth(bar)
            self.position = 1
        elif self.position in [0, 1] and position == -1:
            if self.verbose:
                print(50 * '-')
                print(f'{date} | *** GOING SHORT ***')
            if self.position == 1:
                self.place_sell_order(bar - 1, units=self.units)
            self.place_sell_order(bar - 1,
                                  amount=self.current_balance)
            if self.verbose:
                self.print_net_wealth(bar)
            self.position = -1

In this code the buy and sell order is being called with "bar-1". Should it be "bar+1" instead since the action was predicted using current "bar". If not, can you please clear my misunderstanding?

Thanks,
Debasish

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.