This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json; | |
using System; | |
using System.Collections.Generic; | |
using System.Net.WebSockets; | |
using System.Text; | |
using System.Threading; | |
using System.Threading.Tasks; | |
/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Text.RegularExpressions; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// Example 1. Simple List | |
List<float> floatList = new List<float> { 1.1f, 2.2f, 3.3f, 4.4f, 5.5f }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var lazyString = new Lazy<string>( | |
() => | |
{ | |
// Here you can do some complex processing | |
// and then return a value. | |
Console.WriteLine("Inside lazy loader"); | |
return "Lazy loading!"; | |
}); | |
Console.WriteLine($"Is value created: {lazyString.IsValueCreated}"); // false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
from datetime import datetime | |
from tabulate import tabulate | |
# Illusttration 1. Load some dummy data | |
pd_total_equity = None | |
strategies = [ 'trend_following', 'statsarb', 'triarb' ] | |
strategies_total_equities = {} | |
for strategy in strategies: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"book": "trend_following", | |
"datetime": "20210101", | |
"total_equity": 1000, | |
"turnover": 1000000 | |
}, | |
{ | |
"book": "trend_following", | |
"datetime": "20210201", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import pandas as pd | |
import numpy as np | |
import math | |
from datetime import datetime | |
from tabulate import tabulate | |
# Illustration 1. Array initialization: ones/zeros/arrange/linspace | |
np.arange(0, 10, 2) # array([0, 2, 4, 6, 8]) | |
np.zeros(10) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from keras.models import Sequential | |
from keras.layers import Dense | |
X_train = np.array([[0, 0], [0, 1], [1, 0], [1, 1]]) | |
y_train = np.array([[0], [1], [1], [0]]) | |
model = Sequential() | |
model.add(Dense(2, input_dim=2, activation='relu')) | |
model.add(Dense(1, activation='sigmoid')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class square_all: | |
def __init__(self, numbers): | |
self.numbers = iter(numbers) | |
def __next__(self): | |
return next(self.numbers) ** 2 | |
def __iter__(self): | |
return self |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fibonacci(): | |
a, b = 0, 1 | |
while True: | |
yield a | |
a, b = b, a + b | |
# Generate Fibonacci numbers up to a certain limit | |
def fibonacci_up_to(limit): | |
fib = fibonacci() | |
while True: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MessageWriter(object): | |
def __init__(self, file_name): | |
self.file_name = file_name | |
def __enter__(self): | |
self.file = open(self.file_name, 'w') | |
return self.file | |
def __exit__(self, *args): | |
self.file.close() |