You have to already have these in your system:
- Python. Version 3.6+ is highly recommended.
- Official CPython from python.org
- Anaconda
- (Recommended) Miniconda
You have to already have these in your system:
| """A Simple Strategy Trading Two Stocks | |
| Original code: https://blog.csdn.net/qq_26948675/article/details/80016633 | |
| Modified based on: https://www.backtrader.com/blog/posts/2018-04-22-improving-code/improving-code.html | |
| Replaced the local CSV files with online data from IEX. | |
| Unfortunately, this strategy is not profitable for the two stocks picked. | |
| """ |
| class STLR(torch.optim.lr_scheduler._LRScheduler): | |
| def __init__(self, optimizer, max_mul, ratio, steps_per_cycle, decay=1, last_epoch=-1): | |
| self.max_mul = max_mul - 1 | |
| self.turning_point = steps_per_cycle // (ratio + 1) | |
| self.steps_per_cycle = steps_per_cycle | |
| self.decay = decay | |
| super().__init__(optimizer, last_epoch) | |
| def get_lr(self): | |
| residual = self.last_epoch % self.steps_per_cycle |
| from torchvision import transforms | |
| from PIL import ImageOps | |
| class ResizeAndPad(object): | |
| def __init__(self, size, interpolation=Image.BILINEAR): | |
| assert isinstance(size, int) | |
| self.size = size | |
| self.interpolation = interpolation | |
| def __call__(self, img): |
| tf.reset_default_graph() | |
| graph = tf.Graph() | |
| with graph.as_default(): | |
| tf.set_random_seed(10) | |
| # tf Graph input | |
| X = tf.placeholder("float", [None, timesteps, num_input]) | |
| Y = tf.placeholder("float", [None, num_classes]) | |
| is_training = tf.placeholder("bool") | |
| # Define weights |
| class TemporalConvNet(tf.layers.Layer): | |
| def __init__(self, num_channels, kernel_size=2, dropout=0.2, | |
| trainable=True, name=None, dtype=None, | |
| activity_regularizer=None, **kwargs): | |
| super(TemporalConvNet, self).__init__( | |
| trainable=trainable, dtype=dtype, | |
| activity_regularizer=activity_regularizer, | |
| name=name, **kwargs | |
| ) | |
| self.layers = [] |
| class TemporalBlock(tf.layers.Layer): | |
| def __init__(self, n_outputs, kernel_size, strides, dilation_rate, dropout=0.2, | |
| trainable=True, name=None, dtype=None, | |
| activity_regularizer=None, **kwargs): | |
| super(TemporalBlock, self).__init__( | |
| trainable=trainable, dtype=dtype, | |
| activity_regularizer=activity_regularizer, | |
| name=name, **kwargs | |
| ) | |
| self.dropout = dropout |
| import tensorflow as tf | |
| class CausalConv1D(tf.layers.Conv1D): | |
| def __init__(self, filters, | |
| kernel_size, | |
| strides=1, | |
| dilation_rate=1, | |
| activation=None, | |
| use_bias=True, | |
| kernel_initializer=None, |
| library(checkpoint) | |
| checkpoint("2018-02-25") | |
| library(ggplot2) | |
| # number of people | |
| N <- 1000 | |
| # probability of event interception | |
| P_E <- 0.075 | |
| # probability of lucky event | |
| P_L <- 0.5 |