- Long/Short Equity Strategy
- Market Neutral Strategy
- Merger Arbitrage Strategy
- Convertible Arbitrage Strategy
- Capital Structure Arbitrage Strategy
- Fixed-Income Arbitrage Strategy
- Event-Driven Strategy
- Global Macro Strategy
- Short Only Strategy
2021/12/07
Common hedging strategies
2021/10/21
L1 and L2 loss function
http://www.chioka.in/differences-between-l1-and-l2-as-loss-function-and-regularization/
2021/07/18
Deterministic Finite Automaton (DFA)
https://en.wikipedia.org/wiki/Deterministic_finite_automaton
Check a valid number or a valid decimal number DFA graph:
class Solution(object):
def isNumber(self, s):
# This is the DFA we have designed above
dfa = [
{"digit": 1, "sign": 2, "dot": 3},
{"digit": 1, "dot": 4, "exponent": 5},
{"digit": 1, "dot": 3},
{"digit": 4},
{"digit": 4, "exponent": 5},
{"sign": 6, "digit": 7},
{"digit": 7},
{"digit": 7}
]
current_state = 0
for c in s:
if c.isdigit():
group = "digit"
elif c in ["+", "-"]:
group = "sign"
elif c in ["e", "E"]:
group = "exponent"
elif c == ".":
group = "dot"
else:
return False
if group not in dfa[current_state]:
return False
current_state = dfa[current_state][group]
return current_state in [1, 4, 7]
2021/06/14
Neural Network and super neuron
I have been thinking of this problem for a while now. How human's memory is trigged? For example, you barely think of an event (your friend and you had a great conversation in a club on a rainy night) which happened 20 years ago. However, when you pick up a pen, which was given to you by your friend. Then you suddenly remember some content of the club conversation which took place 20 years ago.
How does a neural network model such brain activity? Here I am proposing a concept of super neuron. This super neuron is a loosely connected neuron in the NN with both a low probability and an associated event (or event summary) stored deeply inside the network.
The event associated with the super neuron has to be trigged by the event. Even more, the probability after the event registered with the system and then the memory flashing up is extremely low.
2021/06/13
Python Collections library
Ref: https://www.geeksforgeeks.org/python-collections-module/
1) Counters
It presents a stat of data
from collections import Counter
Counter({"A":5,"B":2})
array = [''cook","book","took","sook","book","book","aook"]
Counter(array)
2) OrderedDict
It remembers the order when key enters into the dict.
print
(
"\nThis is an Ordered Dict:\n"
)
od
=
OrderedDict()
od[
'a'
]
=
5od[
'b'
]
=
2
od[
'c'
]
=
3
od[
'd'
]
=
4
for
key, value
in
od.items():
print
(key, value)
3) DefaultDict
A DefaultDict is also a sub-class to dictionary. It is used to provide some default values for the key that does not exist and never raises a KeyError.
4) ChainMap
A ChainMap encapsulates many dictionaries into a single unit and returns a list of dictionaries.
from
collections
import
ChainMap
d1
=
{
'a'
:
1
,
'b'
:
2
}
d2
=
{
'c'
:
3
,
'd'
:
4
}
d3
=
{
'e'
:
5
,
'f'
:
6
}
# Defining the chainmap
c
=
ChainMap(d1, d2, d3)
print
(c)
5) NamedTuple
A NamedTuple returns a tuple object with names for each position which the ordinary tuples lack. For example, consider a tuple names student where the first element represents fname, second represents lname and the third element represents the DOB. Suppose for calling fname instead of remembering the index position you can actually call the element by using the fname argument, then it will be really easy for accessing tuples element. This functionality is provided by the NamedTuple.
from collections import namedtuple
# Declaring namedtuple()
Student
=
namedtuple(
'Student'
,[
'name'
,
'age'
,
'DOB'
])
# Adding values
S
=
Student(
'Nandini'
,
'19'
,
'2541997'
)
# Access using index
print
(
"The Student age using index is : "
,end
=
"")
print
(S[
1
])
# Access using name
print
(
"The Student name using keyname is : "
,end
=
"")
print
(S.name)
6. Deque (pronounced deck)
Deque (Doubly Ended Queue) is the optimized list for quicker append and pop operations from both sides of the container. It provides O(1) time complexity for append and pop operations as compared to list with O(n) time complexity.
from
collections
import
deque
# initializing deque
de
=
deque([
1
,
2
,
3
])
# using append() to insert element at right end
# inserts 4 at the end of deque
de.append(
4
)
# printing modified deque
print
(
"The deque after appending at right is : "
)
print
(de)
# using appendleft() to insert element at right end
# inserts 6 at the beginning of deque
de.appendleft(
6
)
# printing modified deque
print
(
"The deque after appending at left is : "
)
print
(de)
7 UserDict
UserDict is a dictionary-like container that acts as a wrapper around the dictionary objects. This container is used when someone wants to create their own dictionary with some modified or new functionality.
# Creating a Dictionary where
# deletion is not allowed
class
MyDict(UserDict):
# Function to stop deleltion
# from dictionary
def
__del__(
self
):
raise
RuntimeError(
"Deletion not allowed"
)
# Function to stop pop from
# dictionary
def
pop(
self
, s
=
None
):
raise
RuntimeError(
"Deletion not allowed"
)
# Function to stop popitem
# from Dictionary
def
popitem(
self
, s
=
None
):
raise
RuntimeError(
"Deletion not allowed"
)
# Driver's code
d
=
MyDict({
'a'
:
1
,
'b'
:
2
,
'c'
:
3
})
d.pop(
1
)
8: UserList
9: UserString
How to Supercharge Your Python Classes with Class Methods
How to Supercharge Your Python Classes with Class Methods | by Siavash Yasini | May, 2024 | Towards Data Science As we just mentioned, a c...
-
https://rszalski.github.io/magicmethods/ __init__ __repr__ __getattr__ __setattr__ __call__(self, [args...]) context manager class Closer: ...
-
Use Celery Celery is an asynchronous task queue based on distributed message passing to distribute workload across machines or threads. A c...
-
https://docs.min.io/docs/python-client-quickstart-guide.html The MinIO Python Client SDK provides simple APIs to access any Amazon S3 com...
-
I am working in the Artificial Intelligence area. I am thinking of two events happened to me. 1) I have the same dream over many years. Wh...
-
Recently, my Mac laptop's (Majove, MacBook Pro (15-inch, 2017)) Safari failed to open. I searched around and could not find a solution. ...