This file contains 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 yfinance as yf | |
import pandas as pd | |
import numpy as np | |
from scipy.stats import norm | |
''' | |
Calculate realised volatility of stock | |
:ticker: yfinance ticker | |
:window: trading days in rolling window |
This file contains 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
# Solution inspired by https://stackoverflow.com/a/33504236/2020801 | |
from xml.sax import ContentHandler, parseString | |
class ExcelHandler(ContentHandler): | |
def __init__(self): | |
self.chars = [] | |
self.cells = [] | |
self.rows = [] | |
self.table = [] | |
self.sheet_name = None |
This file contains 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 scala.concurrent.ExecutionContext.Implicits.global | |
import scala.concurrent.Future | |
class FileApp(val fileCounter: FileCounter) extends Service { | |
private def countWordsV1(number: Int): Future[Int] = fileCounter.countWordsInFile(s"${number}a") | |
.flatMap(c1 => fileCounter.countWordsInFile(s"${number}b").map(c2 => c1 + c2)) | |
private def countWordsV2(number: Int): Future[Int] = { |
This file contains 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
f = Fiber.new do | |
a = 42 | |
loop do | |
Fiber.yield(a) | |
a += 1 | |
end | |
end | |
f.resume # => 42 | |
f.resume # => 43 |
This file contains 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
# calling code: | |
age = user.belongs_to_system_a? ? | |
find_age_from_system_a(name: user.name) : | |
find_age_from_system_b(name: user.name) | |
# methods | |
def find_age_from_system_a(name:) | |
payload = build_payload(name) | |
response = call_system_a(payload) |
This file contains 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
# calling code: | |
age = find_age(name: user.name, divert: !user.belongs_to_system_a?) | |
# methods | |
def find_age(name:, divert:) | |
payload = { name: name, size: 42 } | |
response = divert ? call_system_b(payload) : call_system_a(payload) |