Skip to content

Commit 033f4dd

Browse files
author
todd
committed
Merge remote-tracking branch 'robcarver17/master' into missing-data
2 parents 989e11f + 64f1f2d commit 033f4dd

22 files changed

+459
-326
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ Moved most examples except core to separate git [here](https://github.com/robcar
481481

482482
* Added methods to accountCurveGroup.get_stats(): .mean(), .std(), .tstat(), .pvalue()
483483
* Added method to accountCurveGroup stack; stack object can also produce bootstrap
484-
* Added account_test(ac1, ac2) to produce a t-test statistic for any two account curve like objects.
484+
* Added account_t_test(ac1, ac2) to produce a t-test statistic for any two account curve like objects.
485485

486486
## Version 0.6.0
487487

CONTRIBUTING.md

+40-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# pysystemtrade contributing guide
1+
# Pysystemtrade contributing guide
22

33

4-
## unit tests
4+
## Unit tests
55
This project has a few unit tests. They get run automatically when any PR is
66
submitted. You'll see the result of the run in the PR page. To run the tests
77
yourself locally, before submitting, you'll need `pytest` installed. Then run:
@@ -27,7 +27,7 @@ pytest --runslow
2727
```
2828

2929

30-
## lint
30+
## Lint / Black
3131

3232
This project keeps its code pretty with
3333
[Black](https://black.readthedocs.io/en/stable/). Black gets automatically run
@@ -47,3 +47,40 @@ Note for pycharm users: The blackd plugin requires a blackd daemon to be running
4747
Or, configure your local git install to automatically check and fix your code
4848
as you commit. Configuration instructions
4949
[here](https://black.readthedocs.io/en/stable/integrations/source_version_control.html)
50+
51+
## General code guidelines (INCOMPLETE)
52+
53+
These guidelines are aspirations, and do not describe the system as it stands. The project has been written over a period of several years, and it is only quite recently I've decided to set out some guidelines.
54+
55+
In general, we try and follow the original texts: [PEP 8](https://peps.python.org/pep-0008/) and [clean code](https://gist.github.com/wojteklu/73c6914cc446146b8b533c0988cf8d29).
56+
57+
### General
58+
59+
- Unless there is a single parameter, parameters should be explicit.
60+
- Type hints should be used, with Unions if required `from typing import Union`
61+
62+
63+
### Naming conventions
64+
65+
- For classes, I prefer mixedCase to CamelCase, but single word names should always be Camels.
66+
- Common methods are `get`, `calculate`, `read`, `write`.
67+
- There is a specific procedure for naming objects which form part of the data heirarchy, see [here](https://github.com/robcarver17/pysystemtrade/blob/master/docs/data.md#part-2-overview-of-futures-data-in-pysystemtrade). If this is not followed, then the [automated abstraction of data inside Data 'blob' instances](https://github.com/robcarver17/pysystemtrade/blob/master/docs/data.md#data-blobs) won't work.
68+
- Although arguably redundant, I am a fan of describing eg objects that inherit from dicts with a dict_ prefix. This gives hints as to how they behave without having to look at their code.
69+
70+
71+
### Error handling
72+
73+
- Production code should not throw an error unless things are completely unrecoverable; if it does throw an error it must also log.critical which will email the user
74+
75+
76+
### Caching
77+
78+
FIXME This is a bit of a mess - Update when a unified cache system setup
79+
80+
81+
### Testing
82+
83+
Doc tests should be removed from class methods, since they often require a lot of setup, and make the code harder to read. Unit tests are preferable.
84+
Doc tests make more sense for seperate, standalone, functions.
85+
86+
Test coverage is extremely sparse.

docs/backtesting.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3693,7 +3693,7 @@ returns the two sided t-test statistic and p-value for a null hypothesis of a
36933693
zero mean.
36943694

36953695
Sometimes you might want to compare the performance of two systems, instruments
3696-
or trading rules. The function `from syscore.accounting import account_test`
3696+
or trading rules. The function `from syscore.accounting import account_t_test`
36973697
can be used for this purpose. The two parameters can be anything that looks
36983698
like an account curve, no matter where you got it from.
36993699

syscore/algos.py

-275
This file was deleted.

syscore/capital.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,40 @@
11
"""
2+
WARNING DO NOT REFACTOR NAMES OR LOCATION OF THIS CODE AS IT IS USED IN .YAML FILES, eg
3+
4+
capital_multiplier:
5+
func: syscore.capital.fixed_capital
6+
27
Functions to calculate capital multiplier
38
4-
ALl return Tx1 pd.Series
9+
ALl return Tx1 pd.Series, where a value of 1 is the original capital
10+
11+
See https://qoppac.blogspot.com/2016/06/capital-correction-pysystemtrade.html for more details
12+
513
"""
614
from copy import copy
715
import pandas as pd
816
import numpy as np
17+
from systems.basesystem import System
918

1019

11-
def fixed_capital(system, **ignored_args):
20+
def fixed_capital(system: System, **ignored_args) -> pd.Series:
1221
multiplier = copy(system.accounts.portfolio().percent)
1322
multiplier[:] = 1.0
1423

1524
return multiplier
1625

1726

18-
def full_compounding(system, **ignored_args):
27+
def full_compounding(system: System, **ignored_args) -> pd.Series:
1928
pandl = system.accounts.portfolio().percent
2029
multiplier = 1.0 + (pandl / 100.0)
2130
multiplier = multiplier.cumprod().ffill()
2231

2332
return multiplier
2433

2534

26-
def half_compounding(system, **ignored_args):
35+
def half_compounding(system: System, **ignored_args) -> pd.Series:
36+
37+
## remove any nans
2738
pandl = system.accounts.portfolio().percent.curve().ffill().diff()
2839
multiplier = 1.0
2940
multiplier_list = []

0 commit comments

Comments
 (0)