Skip to content

Instantly share code, notes, and snippets.

@Entity
public class Person {
@Value
private String firstName;
@Value
private String middleName;
@Value
private String lastName;
Person() {}
public class Person {
private final String firstName;
private final Optional<String> middleName;
private final String lastName;
public Person(
String firstName,
Optional<String> middleName,
String lastName) {
Objects.requireNonNull(firstName);
@jeffwf
jeffwf / NPE-3
Last active August 29, 2015 13:57
void rebalancePortfolio(Account account) {
if (account.getPortfolio() != null) {
List<Holding> holdings = account.getPortfolio().getHoldings();
if (holdings != null) {
for (Holding holding : holdings) {
if (holding != null) {
...
}
}
}
@jeffwf
jeffwf / NPE-2
Last active August 29, 2015 13:57
void rebalancePortfolio(Account account) {
if (account != null && account.getPortfolio() != null) {
List<Holding> holdings = account.getPortfolio().getHoldings();
...
}
}
@jeffwf
jeffwf / NPE-1
Last active August 29, 2015 13:57
void rebalancePortfolio(Account account) {
List<Holding> holdings = account.getPortfolio().getHoldings();
...
}
public abstract class InvestmentVehicle extends AllocatedAssetType implements NumberedValue {
private final int number;
private final String name;
private final AssetClass assetClass;
// boilerplate POJO implementation
public static List<? extends InvestmentVehicle> getAll() {...}
public abstract class AllocatedAssetType {
public static List<AllocatedAssetType> getAllAllocatedAssetTypes() {...}
public static final Cash CASH = new Cash();
public static final class Cash extends AllocatedAssetType {
private Cash() {}
sc.sanity.sharpe_ratio=40
sc.sanity.sortino_ratio=20
sc.sanity.information_ratio=0.6
sc.sanity.concentration=2.3
sc.sanity.turnover=9.7
sc.sanity.investing_iq=15
sc.sanity.max_new=5000
sc.sanity.max_missing=5000
sc.sanity.insanity_threshold_percent=10
public final class EtfVehicle extends InvestmentVehicle
{
public static final EtfVehicle E01_EMERGING = new EtfVehicle(1, "E01_EMERGING", AssetClass.INTL_EMERGING, /*VWO*/8901L);
public static final EtfVehicle E02_DEVELOPED = new EtfVehicle(2, "E02_DEVELOPED", AssetClass.INTL_DEVELOPED, /*VEA*/5381L);
public static final EtfVehicle E03_REAL_ESTATE = new EtfVehicle(3, "E03_REAL_ESTATE", AssetClass.REAL_ESTATE, /*VNQ*/4229L);
...
private final InstrumentId instrumentId;
private EtfVehicle(int number, String identity, AssetClass assetClass, InstrumentId instrumentId) {...}
public class EtfModel extends AbstractHibernateEntity {
private Id<EtfModel> id;
private InstrumentId instrumentId;
private AssetClass assetClass;
private DateTime createdAt;
// boilerplate POJO implementation
}