Skip to content

Instantly share code, notes, and snippets.

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Net.WebSockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
/*
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 };
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
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:
@normanlmfung
normanlmfung / json
Created March 30, 2024 08:29
trend_following_total_equity (This is for pandas syntax illustration)
[
{
"book": "trend_following",
"datetime": "20210101",
"total_equity": 1000,
"turnover": 1000000
},
{
"book": "trend_following",
"datetime": "20210201",
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)
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'))
class square_all:
def __init__(self, numbers):
self.numbers = iter(numbers)
def __next__(self):
return next(self.numbers) ** 2
def __iter__(self):
return self
@normanlmfung
normanlmfung / gist:9c293bc8c93c9be7b9ca9fd09c155195
Created March 30, 2024 22:19
python_syntax_yield_return_fibonacci
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:
@normanlmfung
normanlmfung / gist:1765bd4dca5987c352f33304ad91e5f2
Created March 30, 2024 22:21
python_syntax_using_enter_exit
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()