semvec/pypi-packages huggingface dataset:
xrpc-py 0.1.2
An Object-oriented Binary RPC Framework
License: MIT
Requires Python: >=3.8,<4.0


# xrpc

An Object-oriented Binary RPC Framework

## Library Usage

### 1. define service interface (.xidl)
```java
// Greeter.xidl
class HelloReq {
    Str name
}

class HelloReply {
    Str msg
}

class Greeter {
    HelloReply sayHello(HelloReq req)
    sendFile(self, Stream)
}

```

### 2. generate code from xidl
```sh
xrpc-gen python Greeter.xidl
```
will got file `Greeter.py`
```sh
# Greeter.py
    class Greeter 接口定义
    class PrGreeter 代理
    class SrGreeter 服务
```

### 3. 实现服务
1. 继承并实现`SrGreeter`
```py
class GreeterService(SrGreeter):
    def sayHello(req: HelloReq) -> HelloReply:
        print('hello %s' % req.name)
        return HelloReply('Hello, ', req.name)

    def sendFile(file: Stream) -> None:
        save_dir = '__temp/'
        if not os.path.exists(save_dir):
            os.mkdir(save_dir)
        s = FileWriterStream(file, save_dir + file.name)
        self.channel.registerStream(s) # will receive the stream
```

2. 继承并实现默认服务`SrPeer`的查找服务接口

```py
class MyPeerService(SrPeer):
    def getService(name: str) -> IInterface:
        if name == Greeter.__name__:
            return GreeterService(self.channel)
        raise ValueError("service not found!")
```


### 4. 启动服务
```py
config = Config()
peer = MyPeerService(config)
conn = WSConnection() # use websocket
async with conn.start(peer, 'greeter') as (ip, port):
    # server started, show qrcode
    qr = qrcode.QRCode()
    qr.border = 1
    qr.add_data("%s://%s:%d" % (conn.protocol, ip, port))
    qr.print_ascii(invert=True)
    await asyncio.Future() # wait forever

```
> 示例发布了一个名为`greeter`的websocket服务, 该服务可在局域网内自动发现

### 5. 调用服务接口
```py
config = Config()
conn = WSConnection() # use websocket
async with conn.connect('greeter', config) as peer:
    # find service
    obj = await peer.getService(Greeter.__name__)
    greeter = PrGreeter(obj)

    # normal rpc call
    ret = await greeter.sayHello(HelloMsg('Daniel'))
    print(ret.msg) # Hello, Daniel
    
    # Send file
    file = FileReaderStream('file.txt')
    await greeter.sendFile(file) # call sendFile
    await peer.channel.sendStream(file) # send file stream

```
> 查找并连接名为`greeter`的websocket 服务
### 6. 加密握手协议
config中传入handshake即可配置握手协议. 协议实现`HandShakeProtocal`
```py
config = Config(handshake=HandShakeV1())
```
> 握手和加密方式可自定义

### 7. 使用其他的连接协议
目前支持使用websocket(`WSConnection`)和tcp连接协议(`TCPConnection`), 如果想要自定义协议, 请实现`Connection`类
```py
conn = MyCustomConnection() # use custom connection protocal
```

### 8. 局域网发现
默认打开局域网发现功能, 如果想要关闭, 则在启动服务时传入参数`discoverable=False`
```py
async with conn.start(peer, name, discoverable=False) as (ip, port):
    ...
```
out-and-in 1.1
a backward feature elimination followed with forwared features selection strategy.
License: MIT

# out_and_in
 ** out_and_in ** is a backward feature elimination followed with forwared features selection strategy. 

## Basic Idea
This function will itinerary remove one feature and from features, if the metrics has beed optimized, we will add it to dropped-features.
we will drop dropped-features after that repeat, and calculate a metrics based on remaining features, and add those dropped_fatures 
 back to the remaining features, if the performance has been increased, we will remove that features from dropped features. and finially,
it will return dropped features. 


## Instalation
```commandline
pip intall out_and_in
```

## Example
We will use the auto_mpg as demo for the selection process of out_and_in
auto_mpg include 80 features and 1460 entries. those features include 
numerical features and categorical features

```python
import pandas as pd
from main import outin
from sklearn.datasets import fetch_openml
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_squared_error
from math import sqrt

# Load dataset
auto_mpg = fetch_openml(data_id=42165)
X = auto_mpg.data
y = auto_mpg.target
print(f"the shape of X: {X.shape()}")
# encoded X
X_encoded = pd.get_dummies(X, drop_first=True)
# fill NA with mean
X_encoded = X_encoded.fillna(X_encoded.mean())


def model_train(X: pd.DataFrame,
                y: pd.DataFrame):
 """
 This function will train a basic model and return a metric for that model , we take random forest as a example here.
 :param X: pandas dataframe, it will include all features and the categorical features have been encoded.
 :param y: pandas datasrame, it will include prediction target
 :return: metric.
 """

 # Split data into training and testing sets
 X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

 # Initialize the Random Forest model
 rf_model = RandomForestRegressor(n_estimators=100, random_state=42)

 # Train the model
 rf_model.fit(X_train, y_train)

 # Make predictions
 y_pred = rf_model.predict(X_test)

 # Evaluate the model
 rmse = sqrt(mean_squared_error(y_test, y_pred))

 return rmse


# select features
dropped_features = outin(X, y, model_train)
print(f"dropped features: {dropped_features}")
```
finpricing 0.1.0
A pricing library for financial instruments
License: MIT
Requires Python: >=3.9,<3.13

# finpricing

`finpricing` is a Python package designed for advanced financial pricing and risk management. It features pricing models and design patterns that align with industry standards and market conventions. However, it's important to note a few aspects:

1. The industry typically develops pricing libraries in C++ or C# to optimize performance. Speed, however, is not the primary objective of this package. The focus is on presenting rigorous and often overlooked pricing models in a modern, readable language, while ensuring precision.
2. The author's expertise is predominantly in Fixed Income products and derivatives (as of 2023). Contributions to expand the scope of this package are highly encouraged.

The implementation follows the instrument + market + model paradigm. The major modules now (as of 2023/11) are,

- `finpricing.instruments`:
  - Fixed Coupon Bond
  - Credit Default Swap

- `finpricing.markets`:
  - Discount Curve: flat forward assumption, which is the most common curve construction method
  - Survival Curve: piecewise constant hazard rate and Nelson-Siegel-Svensson (NSS) curve
  - CDS Curve (in progress)

- `finpricing.models`:
  - Fixed Bond pricer: risky pricing of fixed coupon bond considering survival curve and recovery rate
  - Bond Basis Solver: solve for the bond basis on top of the discount curve or the survival curve
  - Bond Curve Solver: calibration of the NSS survival curve for a portfolio of bonds of the same issuer by minimizing the bond basis
  - CDS pricer: risky pricing of CDS contracts
  - CDS Par Spreads

- `finpricing.utils` examples:
  - Date: internal date representation
  - Day Count: day count convention, e.g. Actual/360, Actual/365, etc.
  - Calendar: holiday calendar for adjustment of business days
  - Date Generator: generate dates for instrument cash flows

## Installation

```bash
$ pip install finpricing
```

## Usage

## Contributing

Interested in contributing? Check out the contributing guidelines. Please note that this project is released with a Code of Conduct. By contributing to this project, you agree to abide by its terms.

## License

`finpricing` was created by Yiming Zhang. It is licensed under the terms of the MIT license.

## Credits

`finpricing` was created with [`cookiecutter`](https://cookiecutter.readthedocs.io/en/latest/) and the `py-pkgs-cookiecutter` [template](https://github.com/py-pkgs/py-pkgs-cookiecutter).